fix(bindx-dataview): compute real total count for top-level DataGrid (#44)#45
Merged
Merged
Conversation
Top-level <DataGrid> only set the total count lazily, when the current
page returned fewer rows than the page size (`itemCount < queryLimit`) —
i.e. only on a partial last page. On any list spanning more than one full
page, `paging.info.totalCount` / `totalPages` stayed `null`, so the UI
could not show a row count or "page X of Y", and "jump to last page" was
permanently disabled.
Mirror how Contember's react-dataview does it: issue a standalone COUNT
query keyed only on the filter (not on limit/offset), so paging does not
recompute it. Adds a `count` query to the adapter layer (Mock +
Contember, via `paginate<Entity> { pageInfo { totalCount } }`) and a
`useEntityCount` hook, wired into DataGrid, useDataView and SelectDataView.
The partial-page heuristic is kept as a fallback until the count resolves.
`refreshTotalCount()` now drives a recount via a paging refresh token
instead of just nulling the displayed total.
Fixes #44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #44.
Problem
Top-level
<DataGrid>never computed a real total count. It only set the count lazily, when the current page returned fewer rows than the page size (itemCount < queryLimit) — i.e. only on a partial last page. On any list spanning more than one full page,paging.info.totalCount/totalPagesstayednull, so the UI could not show a row count or "page X of Y", and "jump to last page" was permanently disabled (paging.last()early-returns ontotalPages === null). When the total was an exact multiple of the page size, the count was never learned even by paging to the end.Approach
Mirrors how Contember's own
react-dataviewsolves it (useDataViewTotalCount): issue a standalone COUNT query keyed only on the filter — not on limit/offset — so paging through the list does not recompute it, andrefresh()can force a recount.countquery type (CountQuery/CountQueryResult).MockAdapter: counts the filtered set before pagination.ContemberAdapter:paginate<Entity> { pageInfo { totalCount } }, batched into the same request as the sibling list query.useEntityCount(entity, { filter, refreshToken })— new reusable hook in@contember/bindx-reactthat enqueues the count through the existing batcher.DataGrid,useDataViewandSelectDataViewnow feed the count intopaging.setTotalCount(...). The original partial-page heuristic is kept as a fallback until the count resolves (and for adapters that don't implement count queries).refreshTotalCount()now drives a recount via a paging refresh token (PagingStateResult.totalCountRefreshToken) instead of merely nulling the displayed total.Tests
tests/react/dataview/dataGridPaginationTotalCount.test.tsx— the issue's reproduction (multi-page list exposestotalCount/totalPages; last-page jump enabled), now passing.tests/react/dataview/dataGridCountQuery.test.tsx— total reflects the active filter; last-page jump lands on the right rows; count is keyed on the filter, so paging does not re-issue it (verified with a spy adapter).tests/unit/adapter/countQuery.test.ts—MockAdaptercount query (no filter / filtered / unknown entity / independent of limit/offset).All new tests pass;
bun run buildandbun run typecheckare clean. The 10 pre-existing failures onmain(browser/playground "(unnamed)" cases + one form dirty-tracking test) are unrelated and unchanged by this PR.